#include "world.h"
#include "physicsmanager.h"

World::World(Ogre::SceneManager *p_OgreSceneManager)
{
	m_OgreSceneManager = p_OgreSceneManager;

	SetupScene();
}


void World::SetupScene()
{
	// Set the scene's ambient light
	m_OgreSceneManager->setAmbientLight(Ogre::ColourValue(0.5f, 0.40f, 0.40f));

	// Create Object rootnode
	m_ObjectRootNode = m_OgreSceneManager->getRootSceneNode()->createChildSceneNode("WorldRootNode");

	// Create an Entity
	m_Entity = m_OgreSceneManager->createEntity("Tube", "World.mesh");

	// Create a SceneNode and attach the Entity to it
    m_EntityNode = m_ObjectRootNode->createChildSceneNode("WorldEntityNode");

	m_EntityNode->attachObject(m_Entity);

    PhysicsManager::GetInstance()->AddStaticEntity(m_Entity);

}

World::~World()
{
    m_OgreSceneManager->destroyEntity(m_Entity);
    m_OgreSceneManager->getRootSceneNode()->removeAndDestroyChild(m_ObjectRootNode->getName());
    m_Entity = 0;
    m_EntityNode = 0;
}
